package com.yeyv.net.Web.Control.Anonymous;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeyv.net.Annotation.ControllerApi.AnonController;
import com.yeyv.net.UsefulEntity.Resp;
import com.yeyv.net.Web.Entity.GameEntity;
import com.yeyv.net.Web.Service.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@AnonController("/game")
public class GameController {
    @Autowired
    private GameService gameService;

    @PostMapping("/list")
    public Resp<IPage<GameEntity>> list(@RequestBody GameEntity entity) {
        if (entity == null) {
            entity = new GameEntity();
        }
        IPage<GameEntity> page = new Page<>(entity.getPageNo(), entity.getPageSize());
        return Resp.success(gameService.page(page, null));
    }

    @GetMapping("/query")
    public Resp<GameEntity> query(String key) {
        return Resp.success(gameService.getOne(
                new LambdaQueryWrapper<GameEntity>().eq(GameEntity::getKeyword, key)
        ));
    }
}
